home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Drawing / RegionObject.cp < prev    next >
Encoding:
Text File  |  1997-06-28  |  2.6 KB  |  145 lines  |  [TEXT/CWIE]

  1. // RegionObject.cp
  2.  
  3. #ifndef RegionObject_h
  4. #include "RegionObject.h"
  5. #endif
  6. #ifndef QuickDrawError_h
  7. #include "QuickDrawError.h"
  8. #endif
  9.  
  10. RegionObject::RegionObject()
  11.   : me( NewRgn() )
  12.   {
  13.     QuickDrawError::Check().Throw();
  14.     if ( me == 0 )
  15.         throw QuickDrawError( memFullErr );
  16.   }
  17.  
  18. RegionObject::RegionObject( RgnHandle source )
  19.   : me( NewRgn() )
  20.   {
  21.     QuickDrawError::Check().Throw();
  22.     if ( me == 0 )
  23.         throw QuickDrawError( memFullErr );
  24.     
  25.     (*this) = source;
  26.   }
  27.  
  28. RegionObject::RegionObject( const RegionObject& source )
  29.   : me( NewRgn() )
  30.   {
  31.     QuickDrawError::Check().Throw();
  32.     if ( me == 0 )
  33.         throw QuickDrawError( memFullErr );
  34.     
  35.     (*this) = source;
  36.   }
  37.  
  38. RegionObject::RegionObject( const Rect& source )
  39.   : me( NewRgn() )
  40.   {
  41.     QuickDrawError::Check().Throw();
  42.     if ( me == 0 )
  43.         throw QuickDrawError( memFullErr );
  44.     
  45.     (*this) = source;
  46.   }
  47.  
  48. RegionObject& RegionObject::Temporary( const Rect& r )
  49.   {
  50.     static RegionObject temporary;
  51.     temporary = r;
  52.     return temporary;
  53.   }
  54.  
  55. RegionObject& RegionObject::Temporary( RgnHandle r )
  56.   {
  57.     static RegionObject temporary;
  58.     temporary = r;
  59.     return temporary;
  60.   }
  61.  
  62. bool RegionObject::operator==( const Rect& r ) const
  63.   {
  64.     return Rectangular() && Bounds() == r;
  65.   }
  66.  
  67. bool RegionObject::operator<=( const Rect& r ) const
  68.   {
  69.     return Bounds() <= r;
  70.   }
  71.  
  72. bool RegionObject::operator>=( const Rect& r ) const
  73.   {
  74.     RegionObject& temporary( Temporary( r ) );
  75.     temporary -= *this;
  76.     return temporary.IsEmpty();
  77.   }
  78.  
  79. bool RegionObject::operator<=( RgnHandle r ) const
  80.   {
  81.     RegionObject& temporary( Temporary( me ) );
  82.     temporary -= r;
  83.     return temporary.IsEmpty();
  84.   }
  85.  
  86. bool RegionObject::operator>=( RgnHandle r ) const
  87.   {
  88.     RegionObject& temporary( Temporary( r ) );
  89.     temporary -= *this;
  90.     return temporary.IsEmpty();
  91.   }
  92.  
  93. void RegionObject::operator&=( const Rect& r )
  94.   {
  95.     *this &= Temporary( r );
  96.   }
  97.  
  98. void RegionObject::operator|=( const Rect& r )
  99.   {
  100.     *this |= Temporary( r );
  101.   }
  102.  
  103. void RegionObject::operator^=( const Rect& r )
  104.   {
  105.     *this ^= Temporary( r );
  106.   }
  107.  
  108. void RegionObject::operator-=( const Rect& r )
  109.   {
  110.     *this -= Temporary( r );
  111.   }
  112.  
  113. void RegionObject::Complement( const Rect& r )
  114.   {
  115.     Complement( Temporary( r ) );
  116.   }
  117.  
  118. bool RegionObject::Intersects( const Rect& r ) const
  119.   {
  120.     RegionObject& temporary( Temporary( r ) );
  121.     temporary &= *this;
  122.     return !temporary.IsEmpty();
  123.   }
  124.  
  125. bool RegionObject::Intersects( RgnHandle r ) const
  126.   {
  127.     RegionObject& temporary( Temporary( r ) );
  128.     temporary &= *this;
  129.     return !temporary.IsEmpty();
  130.   }
  131.  
  132. void RegionObject::GlobalToLocal()
  133.   {
  134.     PointObject offset( 0, 0 );
  135.     offset.GlobalToLocal();
  136.     *this += offset;
  137.   }
  138.  
  139. void RegionObject::LocalToGlobal()
  140.   {
  141.     PointObject offset( 0, 0 );
  142.     offset.LocalToGlobal();
  143.     *this += offset;
  144.   }
  145.